package com.dkm.dkmproject.service.impl;


import com.dkm.dkmproject.dao.OrderTbMapper;
import com.dkm.dkmproject.domain.OrderTb;
import com.dkm.dkmproject.service.IOrderTbService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dkm.dkmproject.utils.Tools;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author 周佳佳
 * @since 2020-04-26
 */
@Service
public class OrderTbServiceImpl extends ServiceImpl<OrderTbMapper, OrderTb> implements IOrderTbService {

    @Resource
    private OrderTbMapper orderTbMapper;
    @Autowired
    Tools tools;
    @Autowired
    IOrderTbService orderTbService;
    @Override
    public List<OrderTb> QueryOrder(Integer userId,Integer orState) {
        List<OrderTb> list=orderTbMapper.QueryOrder(userId,orState);
        List<OrderTb> list1=new ArrayList<>();
        for (OrderTb orderTb : list) {
            orderTb.setSimpleDate(tools.getTimeStr(orderTb.getOrFwphone()));
            list1.add(orderTb);
        }
        return list1;
    }

    @Override
    public List<OrderTb> selectUserID() {
        return orderTbMapper.selectUserID();
    }

    @Override
    public int selectSqCount(String orId) {
        return orderTbMapper.selectSqCount(orId);
    }

    @Override
    public int addOrderTb(OrderTb orderTb) {
        return orderTbMapper.insert(orderTb);
    }

    @Override
    public int insertSelective(OrderTb record) {
        return orderTbMapper.insertSelective(record);
    }

    @Override
    public List<OrderTb> selectAll(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return orderTbMapper.selectAll();
    }

    @Override
    public int selectCountOne() {
        return orderTbMapper.selectCountOne();
    }

    @Override
    public List<OrderTb> selectAllTwo(Integer pageNum,Integer pageSize,String orFwname) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderTb> list=orderTbMapper.selectAllTwo(orFwname);
        if(list!=null &&list.size()!=0){
            List<OrderTb> listOne=new ArrayList<>();
            for (OrderTb orderTb : list) {
                int count=orderTbService.selectCountTwo(orderTb);
                /**
                 * 传入该业务人员完成业务次数
                 */
                orderTb.setOrIsva(count);
                listOne.add(orderTb);
            }
            return listOne;
        }else{
            return null;
        }
    }

    @Override
    public int selectCountTwo(OrderTb orderTb) {
        return orderTbMapper.selectCountTwo(orderTb);
    }

    @Override
    public int updateByPrimaryKeySelective(OrderTb record) {
        return orderTbMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int selectCountThree(String orFwname) {
        return orderTbMapper.selectCountThree(orFwname);
    }

    @Override
    public OrderTb selectByPrimaryKey(String orId) {
        return orderTbMapper.selectByPrimaryKey(orId);
    }
}
